//
//  ZYCElectiveLevelView.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/23.
//

#import "ZYCElectiveLevelView.h"
@interface ZYCElectiveLevelView ()

// 小学部
@property (nonatomic, strong) UIButton *primaryButton;
//初中部
@property (nonatomic, strong) UIButton *juniorButton;
@property (nonatomic, strong) UIImageView *star;

@property (nonatomic, strong) UIImageView *star1;

@end
@implementation ZYCElectiveLevelView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.primaryButton];
        [self addSubview:self.juniorButton];
        [self.primaryButton addSubview:self.star];
        [self.juniorButton addSubview:self.star1];
        [self.primaryButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self).offset(27.0f);
            make.size.mas_equalTo(CGSizeMake(343.0f, 162.0f));
        }];
        
        [self.juniorButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self.primaryButton.mas_bottom).offset(19.0f);
            make.size.mas_equalTo(self.primaryButton);
        }];
        
        [self.star mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.primaryButton).offset(-17.0f);
            make.top.equalTo(self.primaryButton).offset(17.0f);
            make.size.mas_equalTo(CGSizeMake(18, 18));
        }];
        [self.star1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.juniorButton).offset(-17.0f);
            make.top.equalTo(self.juniorButton).offset(17.0f);
            make.size.mas_equalTo(CGSizeMake(18, 18));
        }];
        
        [self clickElectiveButton:self.primaryButton];
    }
    return self;
}


- (UIImageView *)star {
    if (!_star) {
        _star = [[UIImageView alloc] init];
    }
    return _star;
}

- (UIImageView *)star1 {
    if (!_star1) {
        _star1 = [[UIImageView alloc] init];
    }
    return _star1;
}
- (UIButton *)primaryButton {
    if (!_primaryButton) {
        _primaryButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_primaryButton setTitle:@"小学部" forState:UIControlStateNormal];
        [_primaryButton setTitleColor:HEX_RGB(kTitleWhiteColor) forState:UIControlStateNormal];
        [_primaryButton setBackgroundImage:[UIImage imageNamed:@"czb"] forState:UIControlStateNormal];
        _primaryButton.titleLabel.font = kSystemBoldFont(23.0f);
        _primaryButton.tag = 1000;
        [_primaryButton addTarget:self action:@selector(clickElectiveButton:) forControlEvents:UIControlEventTouchUpInside];
        //去掉系统的按下高亮置灰效果
        [_primaryButton setAdjustsImageWhenHighlighted:NO];

    }
    return _primaryButton;
}

- (UIButton *)juniorButton {
    if (!_juniorButton) {
        _juniorButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_juniorButton setTitle:@"初中部" forState:UIControlStateNormal];
        [_juniorButton setTitleColor:HEX_RGB(kTitleWhiteColor) forState:UIControlStateNormal];
        [_juniorButton setBackgroundImage:[UIImage imageNamed:@"xxb"] forState:UIControlStateNormal];
        _juniorButton.titleLabel.font = kSystemBoldFont(23.0f);
        _juniorButton.tag = 1001;
        [_juniorButton addTarget:self action:@selector(clickElectiveButton:) forControlEvents:UIControlEventTouchUpInside];
        //去掉系统的按下高亮置灰效果
        [_juniorButton setAdjustsImageWhenHighlighted:NO];
    }
    return _juniorButton;
}

- (void)clickElectiveButton:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (sender.tag == 1000) {//小学部
        if (sender.selected) {
            self.type = ZYCElectiveLevelTypePrimary;
            self.star.image = [UIImage imageNamed:@"xx"];
            self.star1.image = [UIImage imageNamed:@"x-1"];
        }

    }else{// 家长
        if (sender.selected) {
            self.star.image = [UIImage imageNamed:@"x-1"];
            self.star1.image = [UIImage imageNamed:@"xx"];
        }
        self.type = ZYCElectiveLevelTypeJunior;
    }
    if ([self.delegate respondsToSelector:@selector(electiveLevelViewDidClick:)]) {
        [self.delegate electiveLevelViewDidClick:self.type];
    }
}


@end
